import { ajax } from '@/utils'

import {
  ActivityItemMovie,
  BannerItem,
  GetCinemaListRes,
  RuleItem
} from './cinemaTypes'

const baseUrl = '/yswy-jdzq-back-service'

import type { GetActivityBrandAreaRes } from './orderTypes'

export default {
  /** 影院列表 */
  getCinemaList(data): Promise<any> {
    return ajax.post(`${baseUrl}/cinema/list`, data)
  },

  /** 规则列表 */
  getRuleList(): Promise<RuleItem[]> {
    return ajax.post(`${baseUrl}/rule/ruleList`)
  },

  /** 编辑规则 */
  editRule(id, ruleContent): Promise<any> {
    return ajax.post(`${baseUrl}/rule/editRule`, { id, ruleContent })
  },

  /** 影院Banner列表 */
  getMoiveBannerList(): Promise<any> {
    return ajax.get(`${baseUrl}/movieBanner/list`)
  },

  /** 设置影院Banner排序 */
  setMoiveBannerSort(data): Promise<any> {
    return ajax.post(`${baseUrl}/movieBanner/sort`, data)
  },

  /** 上下架影院Banner */
  upDownMoiveBanner(id): Promise<any> {
    return ajax.post(`${baseUrl}/movieBanner/upDown/${id}`)
  },

  /** 手动同步影院Banner */
  syncMoiveBanner(): Promise<any> {
    return ajax.post(`${baseUrl}/movieBanner/sync`)
  },

  /** Banner列表 */
  getBannerList(): Promise<BannerItem[]> {
    return ajax.get(`${baseUrl}/banner/list`)
  },

  /** 新增Banner */
  addBanner(item: BannerItem): Promise<any> {
    return ajax.post(`${baseUrl}/banner/add`, item)
  },

  /** 新增Banner */
  editBanner(item: BannerItem): Promise<any> {
    return ajax.put(`${baseUrl}/banner/edit`, item)
  },

  /** 删除Banner */
  deleteBanner(id): Promise<any> {
    return ajax.delete(`${baseUrl}/banner/del/${id}`)
  },

  /** 限时活动列表 */
  getActivityList(data): Promise<any> {
    return ajax.post(`${baseUrl}/cinemaActivity/list`, data)
  },

  /** 影院对应地区 */
  getCinemaArea(): Promise<GetActivityBrandAreaRes> {
    return ajax.get(`${baseUrl}/cinemaActivity/area`)
  },

  /** 活动详情 */
  getActivityDetail(id): Promise<ActivityItemMovie> {
    return ajax.get(`${baseUrl}/cinemaActivity/detail/${id}`)
  },

  /** 新增限时活动 */
  activityAdd(data) {
    return ajax.post(`${baseUrl}/cinemaActivity/add`, data)
  },

  /** 编辑活动 */
  activityEdit(data: ActivityItemMovie) {
    return ajax.put(`${baseUrl}/cinemaActivity/edit`, data)
  },

  /** 活动状态更改 */
  activityChange(id: number) {
    return ajax.put(`${baseUrl}/cinemaActivity/upOrDown/${id}`)
  },

  /** 导出订单 */
  activityExport(id: number) {
    return ajax.get(`${baseUrl}/cinemaActivity/export/${id}`, {
      responseType: 'blob',
      withResponse: true
    })
  },
  /** 导入人 */
  activityImport(data): Promise<any> {
    return ajax.get(`${baseUrl}/cinemaActivity/import`, data)
  },

  /** 订单列表 */
  getOrderList(data): Promise<any> {
    return ajax.post(`${baseUrl}/cinemaOrder/list`, data)
  },

  /** 退款 */
  orderRefund(outTradeNo) {
    return ajax.post(`${baseUrl}/cinemaOrder/afterSale/${outTradeNo}`)
  },

  /** 订单详情 */
  getOrderDetail(orderNo): Promise<any> {
    return ajax.get(`${baseUrl}/cinemaOrder/detail/${orderNo}`)
  },

  /** 电影列表 */
  getMovieList(data): Promise<any> {
    return ajax.post(`${baseUrl}/movie/list`, data)
  },

  /** 电影设置标签 */
  setMovieLabel(id, label): Promise<any> {
    return ajax.post(`${baseUrl}/movie/label`, { id, label })
  },

  /** 电影设置标签 */
  setMovieSort(id, sort): Promise<any> {
    return ajax.post(`${baseUrl}/movie/sort`, { id, sort })
  }
}
